﻿using System;

namespace FDEE.Model
{

    public class MIRebarRecord : RebarBase
    {

        /// <summary>
        /// 根据布置宽度确定MI钢筋
        /// </summary>
        /// <param name="mBarMark"></param>
        /// <param name="sBarMark"></param>
        /// <param name="cBarMark"></param>
        /// <param name="diameter"></param>
        /// <param name="ConsiderLen">承台长度</param>
        /// <param name="Cover">保护层厚度</param>
        /// <param name="bb">B</param>
        /// <param name="cc">C</param>
        /// <param name="quantity"></param>
        /// <param name="shapeConfig"></param>
        public MIRebarRecord(int mBarMark, int sBarMark, string cBarMark, eDB diameter,
            double ConsiderLen,double Cover,double bb,double cc, int quantity, eShapeType shapeConfig)
            : base(mBarMark, sBarMark, cBarMark, diameter, quantity, shapeConfig)
        {
            if ( bb < 0 || cc < 0 )
            {
                throw new Exception("MI结果异常请查询原因！");
            }
            B = (int)Math.Round(ConsiderLen-Cover*2,0,MidpointRounding.AwayFromZero);
            A = (int)Math.Round(bb,0,MidpointRounding.AwayFromZero);
            C = (int)Math.Round(cc,0,MidpointRounding.AwayFromZero);
            this.r = RebarKnowledge.GerRadius(diameter);
            this.d = PublicEnumItems.GeteDBData(diameter.ToString());
            this.Formula = "L=A+B+C-r-2d";
        }


        /// <summary>
        /// 根据布置宽度确定MI钢筋,B=C
        /// </summary>
        /// <param name="mBarMark"></param>
        /// <param name="sBarMark"></param>
        /// <param name="cBarMark"></param>
        /// <param name="diameter"></param>
        /// <param name="ConsiderLen">承台长度</param>
        /// <param name="Cover">保护层厚度</param>
        /// <param name="bb">B</param>
        /// <param name="cc">C</param>
        /// <param name="quantity"></param>
        /// <param name="shapeConfig"></param>
        public MIRebarRecord(int mBarMark, int sBarMark, string cBarMark, eDB diameter,
            double ConsiderLen, double Cover, double bb,  int quantity, eShapeType shapeConfig)
            : base(mBarMark, sBarMark, cBarMark, diameter, quantity, shapeConfig)
        {
            if (bb < 0 )
            {
                throw new Exception("MI(B=C)结果异常请查询原因！");
            }
            B = (int)Math.Round(ConsiderLen - Cover * 2, MidpointRounding.AwayFromZero);
            A = (int)Math.Round(bb, 0, MidpointRounding.AwayFromZero);
            C = (int)Math.Round(bb, 0, MidpointRounding.AwayFromZero);
            this.r = RebarKnowledge.GerRadius(diameter);
            this.d= PublicEnumItems.GeteDBData(diameter.ToString());
            this.Formula = "L=A+B+C-r-2d";
        }


        public override void SetLength()
        {
            Length = Math.Round((A + B + C - r - 2 * d)*0.001, 3, MidpointRounding.AwayFromZero);
            if (Length > 12 || Length < 0)
            {
                throw new Exception("MI长度计算异常，请查找原因！");
            }
        }
    }
  
}
